﻿@using QAS.Nekorama.Common
@using Resources
<!--start!-->
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - @QAS_Nekorama.NEKORAMA_WEBSITE</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Scripts.Render("~/bundles/modernizr")
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryui")
        @Scripts.Render("~/bundles/jqve")
        @Styles.Render("~/Content/css")
        @Styles.Render("~/Content/themes/base/css")
        @RenderSection("scripts", false)
    </head>

    <body>
        <div id="page">
            <!--HEADER-->
            <div id="header">
                <div id="header-container">
                    <div id="main-menu">
                        <ul>
                            <li><a href="/Question/Index">
                                    <img src="~/Images/Header/question-btn.png" /></a>@Html.ActionLink(QAS_Nekorama.QUESTIONS, "Index", "Question")</li>
                            <li><a href="/Tag/Index">
                                    <img src="~/Images/Header/tag-btn.png" /></a>@Html.ActionLink(QAS_Nekorama.TAGS, "Index", "Tag")</li>
                            <li><a href="/User/Index">
                                    <img src="~/Images/Header/user-btn.png" /></a>@Html.ActionLink(QAS_Nekorama.USERS, "Index", "User")</li>
                            <li><a href="/Home/Help">
                                    <img src="~/Images/Header/help-btn.png" /></a>@Html.ActionLink(QAS_Nekorama.HELP, "Help", "Home")</li>
                        </ul>
                    </div>
                    <!--end main-menu-->

                    <div id="pull-right">
                        <nav>
                            <ul>
                                <!--Header Ask Button-->
                                @if (User.Identity.IsAuthenticated && !Helper.IsBanned(WebSecurity.CurrentUserId))
                                {
                                    <li><a href="/Question/Create" title="@QAS_Nekorama.NEW_QUESTION">
                                            <img src="~/Images/Header/ask-btn.png" /></a></li>
                                }
                                <!--Header Language Button-->
                                <li>
                                    <img title="@QAS_Nekorama.LANGUAGE" src="~/Images/@QAS_Nekorama.LANG_BTN" />
                                    <ul>
                                        <li><a id="vi-VN">
                                                <img title="Tiếng Việt" src="~/Images/vn-btn.png" /></a></li>
                                        <li><a id="en-US">
                                                <img title="English" src="~/Images/us-btn.png" /></a></li>
                                        <li><a id="ja-JP">
                                                <img title="日本語" src="~/Images/jp-btn.png" /></a></li>
                                    </ul>
                                </li>
                                <!--Header Login Button-->
                                @Html.Partial("_LoginPartial")

                                <!--Header Search-->
                            @using (Html.BeginForm("Index", "Question", FormMethod.Get, new { @id = "search" }))
                                {
                                    <li>                           
                                    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @id = "tag", name = "tag", value = TempData["tag"], @placeholder = Resources.QAS_Nekorama.SEARCH, size = "25", style = "height: 16px;" })
                                    </li>
                                }
                            </ul>
                        </nav>
                    </div>
                    <!--end pull-right-->
                </div>
                <!--end header-container-->
            </div>
            <!--end header-->

            <!--WRAPPER-->
            <div id="wrapper">
                @RenderSection("featured", false)
                @RenderBody()
                <div id="side-bar">
                    <div class="about">
                        <img src="~/Images/logo.png" />
                        <p>@Html.Raw(AboutPage.ABOUT)</p>
                    </div>
                </div>
                <!--end side-banner-->
            </div>
            <!--end wrapper-->

            <!--FOOTER-->
            <div id="footer">
                <div class="f-content">
                    <p>猫 | @QAS_Nekorama.FOOTER1 | @QAS_Nekorama.FOOTER2 | @QAS_Nekorama.FOOTER3</p>
                </div>
            </div>
            <!--end footer-->
        </div>
        <!--end page-->
    </body>
    <!--end body-->
</html>

<script>
    $(function () {
        var availableTags = [];

        function split(val) {
            return val.split(/,\s*/);
        }

        function extractLast(term) {
            return split(term).pop();
        }

        $("#tag")
        // don't navigate away from the field on tab when selecting an item
            .bind("keyup", function (event) {
                    $.ajax({
                        url: '@Url.Action("GetTags", "Question")',
                        dataType: 'json',
                        data: { tags: $("#tag").val() },
                        success: function (result) {
                            availableTags = result["result"];
                            var tags = $("#tag").val().split(',');
                            $.each(tags, function (key, value) {
                                var index = $.inArray(value.trim(), availableTags);
                                if (index >= 0) {
                                    availableTags.splice(index, 1);
                                }
                            });
                        }
                    });
                    if (event.keyCode === $.ui.keyCode.TAB &&
                    $(this).data("ui-autocomplete").menu.active) {
                        event.preventDefault();
                    }
                })
                .autocomplete({
                    minLength: 0,
                    source: function (request, response) {
                        // delegate back to autocomplete, but extract the last term
                        response($.ui.autocomplete.filter(
                        availableTags, extractLast(request.term)));
                    },
                    focus: function () {
                        // prevent value inserted on focus
                        return false;
                    },
                    select: function (event, ui) {
                        var terms = split(this.value);
                        // remove the current input
                        terms.pop();
                        // add the selected item
                        terms.push(ui.item.value);
                        // add placeholder to get the comma-and-space at the end
                        terms.push("");
                        this.value = terms.join(": ");
                        this.value = "#" + this.value;
                        return false;
                    }

                });
               
    });
</script>

<script>
    $("#vi-VN, #en-US, #ja-JP").live("click", function (e) {
        var culture = $(this).attr("id");
        var cultureobj = new Object();
        cultureobj.culture = culture;
        $.ajax({
            type: 'POST',
            url: "/home/ChangeCulture",
            async: false,
            data: JSON.stringify(cultureobj),
            contentType: 'application/json; charset=utf-8',
            cash: false,
            success: null,
            complete: location.reload()
        });
    });
</script>